package avicit.bdp.oss.utils.stats;

import avicit.bdp.oss.utils.common.Constants;
import avicit.bdp.oss.utils.common.TimeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-11-12
 * @类说明：MetricStats
 * @修改记录：
 * @注意事项：
 * @主要功能:指定bucket的指标统计信息，包括本月PUT/GET请求总数、本月读取量/写入量、最近七天变化信息
 */
public class BucketMetricStats {
    /**
     * 指标1-本月GET请求统计
     */
    private MonthGetReqStats monthGetReqStats;

    /**
     * 指标2-本月PUT请求统计
     */
    private MonthPutReqStats monthPutReaStats;

    /**
     * 指标3-本月读取量统计
     */
    private MonthReadCapacityStats monthReadCapacityStats;

    /**
     * 指标4-本月写入量统计
     */
    private MonthWriteCapacityStats monthWriteCapacityStats;

    /**
     * 指标5-今日读取量
     */
    private DailyReadCapacityStats todayReadCapacityStats;

    /**
     * 指标6-今日写入量
     */
    private DailyWriteCapacityStats todayWriteCapacityStats;

    /**
     * 指标7-今日GET请求数
     */
    private DailyGetReqStats todayGetReqStats;

    /**
     * 指标8-今日PUT请求数
     */
    private DailyPutReqStats todayPutReqStats;

    private MetricTypeEnum metricTypeEnum;

    /**
     * 无参构造函数
     */
    public BucketMetricStats() {
        monthGetReqStats = new MonthGetReqStats();
        monthPutReaStats = new MonthPutReqStats();
        monthReadCapacityStats = new MonthReadCapacityStats();
        monthWriteCapacityStats = new MonthWriteCapacityStats();
        todayReadCapacityStats = new DailyReadCapacityStats();
        todayWriteCapacityStats = new DailyWriteCapacityStats();
        todayGetReqStats = new DailyGetReqStats();
        todayPutReqStats = new DailyPutReqStats();
    }

    public MonthGetReqStats getMonthGetReqStats() {
        return monthGetReqStats;
    }

    public MonthPutReqStats getMonthPutReaStats() {
        return monthPutReaStats;
    }

    public MonthReadCapacityStats getMonthReadCapacityStats() {
        return monthReadCapacityStats;
    }

    public MonthWriteCapacityStats getMonthWriteCapacityStats() {
        return monthWriteCapacityStats;
    }

    public DailyReadCapacityStats getTodayReadCapacityStats() {
        return todayReadCapacityStats;
    }

    public DailyWriteCapacityStats getTodayWriteCapacityStats() {
        return todayWriteCapacityStats;
    }

    public DailyGetReqStats getTodayGetReqStats() {
        return todayGetReqStats;
    }

    public DailyPutReqStats getTodayPutReqStats() {
        return todayPutReqStats;
    }

    public MetricTypeEnum getMetricTypeEnum() {
        return metricTypeEnum;
    }

    public void setMonthGetReqStats(MonthGetReqStats monthGetReqStats) {
        this.monthGetReqStats = monthGetReqStats;
    }

    public void setMonthPutReaStats(MonthPutReqStats monthPutReaStats) {
        this.monthPutReaStats = monthPutReaStats;
    }

    public void setMonthReadCapacityStats(MonthReadCapacityStats monthReadCapacityStats) {
        this.monthReadCapacityStats = monthReadCapacityStats;
    }

    public void setMonthWriteCapacityStats(MonthWriteCapacityStats monthWriteCapacityStats) {
        this.monthWriteCapacityStats = monthWriteCapacityStats;
    }

    public void setTodayReadCapacityStats(DailyReadCapacityStats todayReadCapacityStats) {
        this.todayReadCapacityStats = todayReadCapacityStats;
    }

    public void setTodayWriteCapacityStats(DailyWriteCapacityStats todayWriteCapacityStats) {
        this.todayWriteCapacityStats = todayWriteCapacityStats;
    }

    public void setTodayGetReqStats(DailyGetReqStats todayGetReqStats) {
        this.todayGetReqStats = todayGetReqStats;
    }

    public void setTodayPutReqStats(DailyPutReqStats todayPutReqStats) {
        this.todayPutReqStats = todayPutReqStats;
    }

    public void setMetricTypeEnum(MetricTypeEnum metricTypeEnum) {
        this.metricTypeEnum = metricTypeEnum;
    }

    /**
     * 本月GET请求统计
     */
    public static class MonthGetReqStats {
        /**
         * 本月GET请求数
         */
        private long getReqNum;

        /**
         * 今日GET请求数
         */
        private long dailyGetReqNum;

        /**
         * 日环比
         */
        private String dayOnDayRatio;

        /**
         * 近七天GET请求统计信息;默认最后一个是今日统计值
         */
        List<ReqPara> recentGetReqNum;

        /**
         * 无参构造函数
         */
        public MonthGetReqStats() {
            getReqNum = 0L;
            dailyGetReqNum = 0L;
            dayOnDayRatio = "0.00%";

            recentGetReqNum = new ArrayList<>();
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            // 当天开始时间
            long dayStartTime = TimeUtils.getDailyStartTime(currTime, Constants.TIME_ZONE);
            for (int i = 0; i < Constants.RECENT_DAYS; i++) {
                long startTime = dayStartTime - Constants.DAY_MILLS * (Constants.RECENT_DAYS -1 - i);
                ReqPara reqPara = new ReqPara(startTime, 0L, Constants.NUM_UNIT);
                recentGetReqNum.add(reqPara);
            }
        }

        public MonthGetReqStats(long getReqNum, long dailyGetReqNum, String dayOnDayRatio, List<ReqPara> recentGetReqNum) {
            this.getReqNum = getReqNum;
            this.dailyGetReqNum = dailyGetReqNum;
            this.dayOnDayRatio = dayOnDayRatio;
            this.recentGetReqNum = recentGetReqNum;
        }

        public long getGetReqNum() {
            return getReqNum;
        }

        public long getDailyGetReqNum() {
            return dailyGetReqNum;
        }

        public String getDayOnDayRatio() {
            return dayOnDayRatio;
        }

        public List<ReqPara> getRecentGetReqNum() {
            return recentGetReqNum;
        }

        public void setGetReqNum(long getReqNum) {
            this.getReqNum = getReqNum;
        }

        public void setDailyGetReqNum(long dailyGetReqNum) {
            this.dailyGetReqNum = dailyGetReqNum;
        }

        public void setDayOnDayRatio(String dayOnDayRatio) {
            this.dayOnDayRatio = dayOnDayRatio;
        }

        public void setRecentGetReqNum(List<ReqPara> recentGetReqNum) {
            this.recentGetReqNum = recentGetReqNum;
        }
    }

    /**
     * 本月PUT请求统计
     */
    public static class MonthPutReqStats {
        /**
         * 本月PUT请求数
         */
        private long putReqNum;

        /**
         * 今日PUT请求数
         */
        private long dailyPutReqNum;

        /**
         * 日环比
         */
        private String dayOnDayRatio;
        
        /**
         * 近七天对象PUT请求统计信息;默认最后一个是今日统计值
         */
        List<ReqPara> recentPutReqNum;

        /**
         * 无参构造函数
         */
        public MonthPutReqStats() {
            putReqNum = 0L;
            dailyPutReqNum = 0L;
            dayOnDayRatio = "0.00%";

            recentPutReqNum = new ArrayList<>();
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            // 当天开始时间
            long dayStartTime = TimeUtils.getDailyStartTime(currTime, Constants.TIME_ZONE);
            for (int i = 0; i < Constants.RECENT_DAYS; i++) {
                long startTime = dayStartTime - Constants.DAY_MILLS * (Constants.RECENT_DAYS -1 - i);
                ReqPara reqPara = new ReqPara(startTime, 0L, Constants.NUM_UNIT);
                recentPutReqNum.add(reqPara);
            }
        }

        public MonthPutReqStats(long putReqNum, long dailyPutReqNum, String dayOnDayRatio, List<ReqPara> recentPutReqNum) {
            this.putReqNum = putReqNum;
            this.dailyPutReqNum = dailyPutReqNum;
            this.dayOnDayRatio = dayOnDayRatio;
            this.recentPutReqNum = recentPutReqNum;
        }

        public long getPutReqNum() {
            return putReqNum;
        }

        public long getDailyPutReqNum() {
            return dailyPutReqNum;
        }

        public String getDayOnDayRatio() {
            return dayOnDayRatio;
        }

        public List<ReqPara> getRecentPutReqNum() {
            return recentPutReqNum;
        }

        public void setPutReqNum(long putReqNum) {
            this.putReqNum = putReqNum;
        }

        public void setDailyPutReqNum(long dailyPutReqNum) {
            this.dailyPutReqNum = dailyPutReqNum;
        }

        public void setDayOnDayRatio(String dayOnDayRatio) {
            this.dayOnDayRatio = dayOnDayRatio;
        }

        public void setRecentPutReqNum(List<ReqPara> recentPutReqNum) {
            this.recentPutReqNum = recentPutReqNum;
        }
    }

    /**
     * 本月读取量统计
     */
    public static class MonthReadCapacityStats {
        /**
         * 本月读取量
         */
        private Capacity readCapacity;

        /**
         * 今日读取量
         */
        private Capacity dailyReadCapacity;

        /**
         * 日环比
         */
        private String dayOnDayRatio;
        
        /**
         * 近七天读取量统计信息;默认最后一个是今日统计值
         */
        List<TrafficPara> recentReadCapacity;

        /**
         * 无参构造函数
         */
        public MonthReadCapacityStats() {
            readCapacity = new Capacity(0.0, Constants.KB_UNIT);
            dailyReadCapacity = new Capacity(0.0, Constants.KB_UNIT);
            dayOnDayRatio = "0.00%";

            recentReadCapacity = new ArrayList<>();
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            // 当天开始时间
            long dayStartTime = TimeUtils.getDailyStartTime(currTime, Constants.TIME_ZONE);
            for (int i = 0; i < Constants.RECENT_DAYS; i++) {
                long startTime = dayStartTime - Constants.DAY_MILLS * (Constants.RECENT_DAYS -1 - i);
                TrafficPara trafficPara = new TrafficPara(startTime, 0L, Constants.KB_UNIT);
                recentReadCapacity.add(trafficPara);
            }
        }

        public MonthReadCapacityStats(Capacity readCapacity, Capacity dailyReadCapacity, String dayOnDayRatio,
                                      List<TrafficPara> recentReadCapacity) {
            this.readCapacity = readCapacity;
            this.dailyReadCapacity = dailyReadCapacity;
            this.dayOnDayRatio = dayOnDayRatio;
            this.recentReadCapacity = recentReadCapacity;
        }

        public Capacity getReadCapacity() {
            return readCapacity;
        }

        public Capacity getDailyReadCapacity() {
            return dailyReadCapacity;
        }

        public String getDayOnDayRatio() {
            return dayOnDayRatio;
        }

        public List<TrafficPara> getRecentReadCapacity() {
            return recentReadCapacity;
        }

        public void setReadCapacity(Capacity readCapacity) {
            this.readCapacity = readCapacity;
        }

        public void setDailyReadCapacity(Capacity dailyReadCapacity) {
            this.dailyReadCapacity = dailyReadCapacity;
        }

        public void setDayOnDayRatio(String dayOnDayRatio) {
            this.dayOnDayRatio = dayOnDayRatio;
        }

        public void setRecentReadCapacity(List<TrafficPara> recentReadCapacity) {
            this.recentReadCapacity = recentReadCapacity;
        }
    }

    /**
     * 本月写入量统计
     */
    public static class MonthWriteCapacityStats {
        /**
         * 本月写入量
         */
        private Capacity writeCapacity;

        /**
         * 今日写入量
         */
        private Capacity dailyWriteCapacity;

        /**
         * 日环比
         */
        private String dayOnDayRatio;
        
        /**
         * 近七天对象写入量统计信息;默认最后一个是今日统计值
         */
        List<TrafficPara> recentWriteCapacity;

        /**
         * 无参构造函数
         */
        public MonthWriteCapacityStats() {
            writeCapacity = new Capacity(0.0, Constants.KB_UNIT);
            dailyWriteCapacity = new Capacity(0.0, Constants.KB_UNIT);
            dayOnDayRatio = "0.00%";

            recentWriteCapacity = new ArrayList<>();
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            // 当天开始时间
            long dayStartTime = TimeUtils.getDailyStartTime(currTime, Constants.TIME_ZONE);
            for (int i = 0; i < Constants.RECENT_DAYS; i++) {
                long startTime = dayStartTime - Constants.DAY_MILLS * (Constants.RECENT_DAYS -1 - i);
                TrafficPara trafficPara = new TrafficPara(startTime, 0L, Constants.KB_UNIT);
                recentWriteCapacity.add(trafficPara);
            }
        }

        public MonthWriteCapacityStats(Capacity writeCapacity, Capacity dailyWriteCapacity, String dayOnDayRatio, List<TrafficPara> recentWriteCapacity) {
            this.writeCapacity = writeCapacity;
            this.dailyWriteCapacity = dailyWriteCapacity;
            this.dayOnDayRatio = dayOnDayRatio;
            this.recentWriteCapacity = recentWriteCapacity;
        }

        public Capacity getWriteCapacity() {
            return writeCapacity;
        }

        public Capacity getDailyWriteCapacity() {
            return dailyWriteCapacity;
        }

        public String getDayOnDayRatio() {
            return dayOnDayRatio;
        }

        public List<TrafficPara> getRecentWriteCapacity() {
            return recentWriteCapacity;
        }

        public void setWriteCapacity(Capacity writeCapacity) {
            this.writeCapacity = writeCapacity;
        }

        public void setDailyWriteCapacity(Capacity dailyWriteCapacity) {
            this.dailyWriteCapacity = dailyWriteCapacity;
        }

        public void setDayOnDayRatio(String dayOnDayRatio) {
            this.dayOnDayRatio = dayOnDayRatio;
        }

        public void setRecentWriteCapacity(List<TrafficPara> recentWriteCapacity) {
            this.recentWriteCapacity = recentWriteCapacity;
        }
    }

    /**
     * 今日读取量
     */
    public static class DailyReadCapacityStats {
        /**
         * 最大读取量
         */
        private Capacity maxReadCapacity;

        /**
         * 最小读取量
         */
        private Capacity minReadCapacity;

        /**
         * 横轴，时间
         */
        private List<Long> horizontalList;

        /**
         * 纵轴，读取量
         */
        private List<TrafficPara> verticalList;

        /**
         * 具体读取量
         */
        private List<TrafficPara> values;

        /**
         * 无参构造函数
         */
        public DailyReadCapacityStats() {
            maxReadCapacity = new Capacity(0.0, Constants.KB_UNIT);
            minReadCapacity = new Capacity(0.0, Constants.KB_UNIT);

            // 横轴初始化
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            horizontalList = new ArrayList<>();
            for (int i = 0; i < Constants.RECENT_HOURS; i++) {
                long time = currTime - Constants.ONE_HOUR_MILLS * (Constants.RECENT_HOURS - i - 1);
                horizontalList.add(time);
            }

            // 纵轴初始化
            verticalList = new ArrayList<>();
            for (int i = 0; i < Constants.NUM_FIVE; i++) {
                TrafficPara para = new TrafficPara(0L, Constants.DEFAULT_VERTICAL_STEP * i, Constants.KB_UNIT);
                verticalList.add(para);
            }

            values = new ArrayList<>();
        }

        public DailyReadCapacityStats(Capacity maxReadCapacity, Capacity minReadCapacity, List<Long> horizontalList, List<TrafficPara> verticalList, List<TrafficPara> values) {
            this.maxReadCapacity = maxReadCapacity;
            this.minReadCapacity = minReadCapacity;
            this.horizontalList = horizontalList;
            this.verticalList = verticalList;
            this.values = values;
        }

        public Capacity getMaxReadCapacity() {
            return maxReadCapacity;
        }

        public Capacity getMinReadCapacity() {
            return minReadCapacity;
        }

        public List<Long> getHorizontalList() {
            return horizontalList;
        }

        public List<TrafficPara> getVerticalList() {
            return verticalList;
        }

        public List<TrafficPara> getValues() {
            return values;
        }

        public void setMaxReadCapacity(Capacity maxReadCapacity) {
            this.maxReadCapacity = maxReadCapacity;
        }

        public void setMinReadCapacity(Capacity minReadCapacity) {
            this.minReadCapacity = minReadCapacity;
        }

        public void setHorizontalList(List<Long> horizontalList) {
            this.horizontalList = horizontalList;
        }

        public void setVerticalList(List<TrafficPara> verticalList) {
            this.verticalList = verticalList;
        }

        public void setValues(List<TrafficPara> values) {
            this.values = values;
        }
    }

    /**
     * 今日写入量
     */
    public static class DailyWriteCapacityStats {
        /**
         * 最大写入量
         */
        private Capacity maxWriteCapacity;

        /**
         * 最小写入量
         */
        private Capacity minWriteCapacity;

        /**
         * 横轴，时间
         */
        private List<Long> horizontalList;

        /**
         * 纵轴，写入量
         */
        private List<TrafficPara> verticalList;

        /**
         * 具体写入量
         */
        private List<TrafficPara> values;

        /**
         * 无参构造函数
         */
        public DailyWriteCapacityStats() {
            maxWriteCapacity = new Capacity(0.0, Constants.KB_UNIT);
            minWriteCapacity = new Capacity(0.0, Constants.KB_UNIT);

            // 横轴初始化
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            horizontalList = new ArrayList<>();
            for (int i = 0; i < Constants.RECENT_HOURS; i++) {
                long time = currTime - Constants.ONE_HOUR_MILLS * (Constants.RECENT_HOURS - i - 1);
                horizontalList.add(time);
            }

            // 纵轴初始化
            verticalList = new ArrayList<>();
            for (int i = 0; i < Constants.NUM_FIVE; i++) {
                TrafficPara para = new TrafficPara(0L, Constants.DEFAULT_VERTICAL_STEP * i, Constants.KB_UNIT);
                verticalList.add(para);
            }

            values = new ArrayList<>();
        }

        public DailyWriteCapacityStats(Capacity maxWriteCapacity, Capacity minWriteCapacity, List<Long> horizontalList, List<TrafficPara> verticalList, List<TrafficPara> values) {
            this.maxWriteCapacity = maxWriteCapacity;
            this.minWriteCapacity = minWriteCapacity;
            this.horizontalList = horizontalList;
            this.verticalList = verticalList;
            this.values = values;
        }

        public Capacity getMaxWriteCapacity() {
            return maxWriteCapacity;
        }

        public Capacity getMinWriteCapacity() {
            return minWriteCapacity;
        }

        public List<Long> getHorizontalList() {
            return horizontalList;
        }

        public List<TrafficPara> getVerticalList() {
            return verticalList;
        }

        public List<TrafficPara> getValues() {
            return values;
        }

        public void setMaxWriteCapacity(Capacity maxWriteCapacity) {
            this.maxWriteCapacity = maxWriteCapacity;
        }

        public void setMinWriteCapacity(Capacity minWriteCapacity) {
            this.minWriteCapacity = minWriteCapacity;
        }

        public void setHorizontalList(List<Long> horizontalList) {
            this.horizontalList = horizontalList;
        }

        public void setVerticalList(List<TrafficPara> verticalList) {
            this.verticalList = verticalList;
        }

        public void setValues(List<TrafficPara> values) {
            this.values = values;
        }
    }

    /**
     * 今日GET请求数
     */
    public static class DailyGetReqStats {
        /**
         * 最大GET请求数
         */
        private long maxGetReq;

        /**
         * 最小GET请求数
         */
        private long minGetReq;

        /**
         * 横轴，时间
         */
        private List<Long> horizontalList;

        /**
         * 纵轴，GET请求数
         */
        private List<ReqPara> verticalList;

        /**
         * 具体GET请求数
         */
        private List<ReqPara> values;

        /**
         * 无参构造函数
         */
        public DailyGetReqStats() {
            maxGetReq = 0L;
            minGetReq = 0L;

            // 横轴初始化
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            horizontalList = new ArrayList<>();
            for (int i = 0; i < Constants.RECENT_HOURS; i++) {
                long time = currTime - Constants.ONE_HOUR_MILLS * (Constants.RECENT_HOURS - i - 1);
                horizontalList.add(time);
            }

            // 纵轴初始化
            verticalList = new ArrayList<>();
            for (int i = 0; i < Constants.NUM_FIVE; i++) {
                ReqPara para = new ReqPara(0L, (long) Constants.DEFAULT_VERTICAL_STEP * i, Constants.NUM_UNIT);
                verticalList.add(para);
            }

            values = new ArrayList<>();
        }

        public DailyGetReqStats(long maxGetReq, long minGetReq, List<Long> horizontalList, List<ReqPara> verticalList, List<ReqPara> values) {
            this.maxGetReq = maxGetReq;
            this.minGetReq = minGetReq;
            this.horizontalList = horizontalList;
            this.verticalList = verticalList;
            this.values = values;
        }

        public long getMaxGetReq() {
            return maxGetReq;
        }

        public long getMinGetReq() {
            return minGetReq;
        }

        public List<Long> getHorizontalList() {
            return horizontalList;
        }

        public List<ReqPara> getVerticalList() {
            return verticalList;
        }

        public List<ReqPara> getValues() {
            return values;
        }

        public void setMaxGetReq(long maxGetReq) {
            this.maxGetReq = maxGetReq;
        }

        public void setMinGetReq(long minGetReq) {
            this.minGetReq = minGetReq;
        }

        public void setHorizontalList(List<Long> horizontalList) {
            this.horizontalList = horizontalList;
        }

        public void setVerticalList(List<ReqPara> verticalList) {
            this.verticalList = verticalList;
        }

        public void setValues(List<ReqPara> values) {
            this.values = values;
        }
    }

    /**
     * 今日PUT请求数
     */
    public static class DailyPutReqStats {
        /**
         * 最大PUT请求数
         */
        private long maxPutReq;

        /**
         * 最小PUT请求数
         */
        private long minPutReq;

        /**
         * 横轴，时间
         */
        private List<Long> horizontalList;

        /**
         * 纵轴，PUT请求数
         */
        private List<ReqPara> verticalList;

        /**
         * 具体PUT请求数
         */
        private List<ReqPara> values;

        /**
         * 无参构造函数
         */
        public DailyPutReqStats() {
            maxPutReq = 0L;
            minPutReq = 0L;

            // 横轴初始化
            // 获取当前系统时间
            long currTime = System.currentTimeMillis();
            horizontalList = new ArrayList<>();
            for (int i = 0; i < Constants.RECENT_HOURS; i++) {
                long time = currTime - Constants.ONE_HOUR_MILLS * (Constants.RECENT_HOURS - i - 1);
                horizontalList.add(time);
            }

            // 纵轴初始化
            verticalList = new ArrayList<>();
            for (int i = 0; i < Constants.NUM_FIVE; i++) {
                ReqPara para = new ReqPara(0L, (long) Constants.DEFAULT_VERTICAL_STEP * i, Constants.NUM_UNIT);
                verticalList.add(para);
            }

            values = new ArrayList<>();
        }

        public DailyPutReqStats(long maxPutReq, long minPutReq, List<Long> horizontalList, List<ReqPara> verticalList, List<ReqPara> values) {
            this.maxPutReq = maxPutReq;
            this.minPutReq = minPutReq;
            this.horizontalList = horizontalList;
            this.verticalList = verticalList;
            this.values = values;
        }

        public long getMaxPutReq() {
            return maxPutReq;
        }

        public long getMinPutReq() {
            return minPutReq;
        }

        public List<Long> getHorizontalList() {
            return horizontalList;
        }

        public List<ReqPara> getVerticalList() {
            return verticalList;
        }

        public List<ReqPara> getValues() {
            return values;
        }

        public void setMaxPutReq(long maxPutReq) {
            this.maxPutReq = maxPutReq;
        }

        public void setMinPutReq(long minPutReq) {
            this.minPutReq = minPutReq;
        }

        public void setHorizontalList(List<Long> horizontalList) {
            this.horizontalList = horizontalList;
        }

        public void setVerticalList(List<ReqPara> verticalList) {
            this.verticalList = verticalList;
        }

        public void setValues(List<ReqPara> values) {
            this.values = values;
        }
    }
}
